package com.zhanglinwei.common.utils;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Collection;
import java.util.function.Supplier;

public final class AssertUT {

    private AssertUT(){}

    public static void isTrue(boolean expression, String message) {
        if (!expression) {
            throw new IllegalArgumentException(message);
        }
    }

    public static void isTrue(boolean expression, Supplier<? extends RuntimeException> exceptionSupplier) {
        if (!expression) {
            throw exceptionSupplier.get();
        }
    }

    public static void isFalse(boolean expression, String message) {
        if (expression) {
            throw new IllegalArgumentException(message);
        }
    }

    public static void isFalse(boolean expression, Supplier<? extends RuntimeException> exceptionSupplier) {
        if (expression) {
            throw exceptionSupplier.get();
        }
    }

    public static void isNull(Object object, String message) {
        if (object != null) {
            throw new IllegalArgumentException(message);
        }
    }

    public static void isNull(Object object, Supplier<? extends RuntimeException> exceptionSupplier) {
        if (object != null) {
            throw exceptionSupplier.get();
        }
    }

    public static void notNull(Object object, String message) {
        if (object == null) {
            throw new IllegalArgumentException(message);
        }
    }

    public static void notNull(Object object, Supplier<? extends RuntimeException> exceptionSupplier) {
        if (object == null) {
            throw exceptionSupplier.get();
        }
    }

    public static void notEmpty(Collection<?> collection, String message) {
        if (CollectionUtils.isEmpty(collection)) {
            throw new IllegalArgumentException(message);
        }
    }

    public static void notEmpty(Collection<?> collection, Supplier<? extends RuntimeException> exceptionSupplier) {
        if (CollectionUtils.isEmpty(collection)) {
            throw exceptionSupplier.get();
        }
    }

    public static void isEmpty(Collection<?> collection, String message) {
        if (CollectionUtils.isNotEmpty(collection)) {
            throw new IllegalArgumentException(message);
        }
    }
    public static void isEmpty(Collection<?> collection, Supplier<? extends RuntimeException> exceptionSupplier) {
        if (CollectionUtils.isNotEmpty(collection)) {
            throw exceptionSupplier.get();
        }
    }

    public static void notBlank(CharSequence cs, String message) {
        if (StringUtils.isBlank(cs)) {
            throw new IllegalArgumentException(message);
        }
    }

    public static void notBlank(CharSequence cs, Supplier<? extends RuntimeException> exceptionSupplier) {
        if (StringUtils.isBlank(cs)) {
            throw exceptionSupplier.get();
        }
    }

}
